These constants are used in various files.
If you need to define a value that will be used in those files, just define it here rather than copying it across each file, so that it will be easy to change it if you need to.
module_constants.py is a very simple file: It is filled with constants -- you should already know a bit about them from reading the section Variables of this documentation. The constants defined here work exactly the same way as constants defined anywhere else. However, constants which are used in multiple module files should be defined in module_constants.py so that the module system always knows where to find them. It also serves as an organised, easily-accessible list where you can change the value of a constant whenever you might need to. Any changes will immediately affect all operations and scripts using the constant, so you don't have to manually find and replace them. For example, changing
hero_escape_after_defeat_chance = 80
to
hero_escape_after_defeat_chance = 50
would immediately change any operations or scripts using hero_escape_after_defeat_chance, treating the constant as the value 50 instead of the value 80.
This file also stores the range markers such as kings_begin = "trp_kingdom_1_lord" and kings_end = "trp_knight_1_1". It is recommended to first look up these ranges and to get a grasp of them since, to stay with the example of troops, it determines at which places in module_troops.py you should implement new kings, merchants, mercenaries, etc..
Another powerful tool defined in the constants section is the use of slots about which you should already have read about in section Slots. Slots can be assigned to any tuple object (troops, factions, parties, quest, etc.) and can store a specific value that is used by all in that object type. These are used as indices by the Module System for object_get/set_slot to fetch and/or store data in array format for the various objects that exist in-game.[1] Let's look at where the definition for quest slots are listed as an example:
###################################################
## QUEST SLOTS
###################################################
slot_quest_target_center = 1
slot_quest_target_troop = 2
slot_quest_target_faction = 3
slot_quest_object_troop = 4
##slot_quest_target_troop_is_prisoner = 5
slot_quest_giver_troop = 6
slot_quest_object_center = 7
slot_quest_target_party = 8
slot_quest_target_party_template = 9
slot_quest_target_amount = 10
slot_quest_current_state = 11
slot_quest_giver_center = 12
slot_quest_target_dna = 13
slot_quest_target_item = 14
slot_quest_object_faction = 15
slot_quest_convince_value = 19
slot_quest_importance = 20
slot_quest_xp_reward = 21
slot_quest_gold_reward = 22
slot_quest_expiration_days = 23
slot_quest_dont_give_again_period = 24
slot_quest_dont_give_again_remaining_days = 25
###################################################
On the left side of the = are the names given to each slot. The slot number is on the right side of the =. The names make it easier to know what the slot is used for. To be specific, slot_quest_xp_reward is used by native code to store how much XP you get from completing the quest. When referencing this value, you can either reference it as slot_quest_xp_reward or by the number 21. When looking through the code it's easier to understand the name over the number.
If you want to add slots, simply define your new slot to be any value - if it's too high, then objects will reserve memory up to that index and there will be a performance issues. If you define it to be a value that already exists, then the game will simply use the same space for both - it doesn't really care what name you give it. Is your item for example a gun, you can safely use the same slot as food or books - item slots are rarely used in Native anyways. After you've done so, simply use (item_set_slot, "itm_gun", slot_item_whatever, val) from anywhere to store a value. This is always a number but that number can be a reference to another object - for example snd_lyhyt from module_sounds.py. Notice that the reference without quotes takes on the index value generated in id_sounds.py, while the quoted reference has probably the same value bitshifted to prevent conflicts.[2]
Make sure that the files at which you use the here implemented constants are referencing to module_constants.py via from module_constants import * at the top of the file, otherwise you might encounter an error at compiling.